home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / play / splib43U.lha / superplay-lib_USR / SuperPlay / SuperPlay_Main.c < prev    next >
C/C++ Source or Header  |  1994-12-13  |  7KB  |  239 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Andreas R. Kleinert
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include "SuperPlay_Main.h"
  24.  
  25. struct Screen         *Scr = NULL;
  26. UBYTE                 *PubScreenName = "Workbench";
  27. APTR                   VisualInfo = NULL;
  28. struct Window         *SP_Main_Wnd = NULL;
  29. struct Gadget         *SP_Main_GList = NULL;
  30. struct Gadget         *SP_Main_Gadgets[9];
  31. UWORD                  SP_Main_Left = 0;
  32. UWORD                  SP_Main_Top = 11;
  33. UWORD                  SP_Main_Width = 501;
  34. UWORD                  SP_Main_Height = 54;
  35. UBYTE                 *SP_Main_Wdt = (UBYTE *)"SuperPlay V4.1, © 1994 by Andreas R. Kleinert";
  36. struct TextAttr       *Font, Attr;
  37. UWORD                  FontX, FontY;
  38. UWORD                  OffX, OffY;
  39.  
  40. extern struct MinList SPOGad0List;
  41.  
  42. struct Node SPOGad0Nodes[] = {
  43.     &SPOGad0Nodes[1], ( struct Node * )&SPOGad0List.mlh_Head, 0, 0, "8SVX",
  44.     &SPOGad0Nodes[2], &SPOGad0Nodes[0], 0, 0, "VOC",
  45.     &SPOGad0Nodes[3], &SPOGad0Nodes[1], 0, 0, "WAV",
  46.     ( struct Node * )&SPOGad0List.mlh_Tail, &SPOGad0Nodes[2], 0, 0, "SPO" };
  47.  
  48. struct MinList SPOGad0List = {
  49.     ( struct MinNode * )&SPOGad0Nodes[0], ( struct MinNode * )NULL, ( struct MinNode * )&SPOGad0Nodes[3] };
  50.  
  51. struct IntuiText SP_Main_IText[] = {
  52.     2, 0, JAM1,147, 48, NULL, (UBYTE *)"Player/Converter. Freeware.", NULL };
  53.  
  54. #define SP_Main__TNUM 1
  55.  
  56. UWORD SP_Main_GTypes[] = {
  57.     BUTTON_KIND,
  58.     BUTTON_KIND,
  59.     BUTTON_KIND,
  60.     BUTTON_KIND,
  61.     BUTTON_KIND,
  62.     BUTTON_KIND,
  63.     BUTTON_KIND,
  64.     BUTTON_KIND,
  65.     LISTVIEW_KIND
  66. };
  67.  
  68. struct NewGadget SP_Main_NGad[] = {
  69.     83, 29, 207, 12, (UBYTE *)"Load and _Convert to :", NULL, GD_ConvertGad, PLACETEXT_IN, NULL, NULL,
  70.     3, 1, 113, 12, (UBYTE *)"Load and _Play", NULL, GD_PlayGad, PLACETEXT_IN, NULL, NULL,
  71.     3, 13, 45, 12, (UBYTE *)"_Stop", NULL, GD_StopGad, PLACETEXT_IN, NULL, NULL,
  72.     49, 13, 82, 12, (UBYTE *)"Con_tinue", NULL, GD_ContGad, PLACETEXT_IN, NULL, NULL,
  73.     132, 13, 76, 12, (UBYTE *)"_Forward", NULL, GD_ForGad, PLACETEXT_IN, NULL, NULL,
  74.     209, 13, 82, 12, (UBYTE *)"_Backward", NULL, GD_BackGad, PLACETEXT_IN, NULL, NULL,
  75.     117, 1, 174, 12, (UBYTE *)"Get File _Information", NULL, GD_InfoGad, PLACETEXT_IN, NULL, NULL,
  76.     3, 29, 79, 12, (UBYTE *)"_LED", NULL, GD_LEDGad, PLACETEXT_IN, NULL, NULL,
  77.     291, 1, 209, 40, NULL, NULL, GD_SPOGad, 0, NULL, NULL
  78. };
  79.  
  80. ULONG SP_Main_GTags[] = {
  81.     (GT_Underscore), '_', (TAG_DONE),
  82.     (GT_Underscore), '_', (TAG_DONE),
  83.     (GT_Underscore), '_', (TAG_DONE),
  84.     (GT_Underscore), '_', (TAG_DONE),
  85.     (GT_Underscore), '_', (TAG_DONE),
  86.     (GT_Underscore), '_', (TAG_DONE),
  87.     (GT_Underscore), '_', (TAG_DONE),
  88.     (GT_Underscore), '_', (TAG_DONE),
  89.     (GTLV_Labels), (ULONG)&SPOGad0List, (GTLV_ShowSelected), NULL, (LAYOUTA_Spacing), 1, (TAG_DONE)
  90. };
  91.  
  92. static UWORD ComputeX( UWORD value )
  93. {
  94.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  95. }
  96.  
  97. static UWORD ComputeY( UWORD value )
  98. {
  99.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  100. }
  101.  
  102. static void ComputeFont( UWORD width, UWORD height )
  103. {
  104.     Font = &Attr;
  105.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  106.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  107.     FontX = Scr->RastPort.Font->tf_XSize;
  108.  
  109.     OffX = Scr->WBorLeft;
  110.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  111.  
  112.     if ( width && height ) {
  113.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  114.             goto UseTopaz;
  115.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  116.             goto UseTopaz;
  117.     }
  118.     return;
  119.  
  120. UseTopaz:
  121.     Font->ta_Name = (STRPTR)"topaz.font";
  122.     FontX = FontY = Font->ta_YSize = 8;
  123. }
  124.  
  125. int SetupScreen( void )
  126. {
  127.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  128.         return( 1L );
  129.  
  130.     ComputeFont( 0, 0 );
  131.  
  132.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  133.         return( 2L );
  134.  
  135.     return( 0L );
  136. }
  137.  
  138. void CloseDownScreen( void )
  139. {
  140.     if ( VisualInfo ) {
  141.         FreeVisualInfo( VisualInfo );
  142.         VisualInfo = NULL;
  143.     }
  144.  
  145.     if ( Scr        ) {
  146.         UnlockPubScreen( NULL, Scr );
  147.         Scr = NULL;
  148.     }
  149. }
  150.  
  151. void SP_Main_Render( void )
  152. {
  153.     struct IntuiText    it;
  154.     UWORD            cnt;
  155.  
  156.     ComputeFont( SP_Main_Width, SP_Main_Height );
  157.  
  158.  
  159.     for ( cnt = 0; cnt < SP_Main__TNUM; cnt++ ) {
  160.         CopyMem(( char * )&SP_Main_IText[ cnt ], ( char * )&it, (long)sizeof( struct IntuiText ));
  161.         it.ITextFont = Font;
  162.         it.LeftEdge  = OffX + ComputeX( it.LeftEdge ) - ( IntuiTextLength( &it ) >> 1 );
  163.         it.TopEdge   = OffY + ComputeY( it.TopEdge ) - ( Font->ta_YSize >> 1 );
  164.         PrintIText( SP_Main_Wnd->RPort, &it, 0, 0 );
  165.     }
  166. }
  167.  
  168. int OpenSP_Main_Window( void )
  169. {
  170.     struct NewGadget    ng;
  171.     struct Gadget    *g;
  172.     UWORD        lc, tc;
  173.     UWORD        wleft = SP_Main_Left, wtop = SP_Main_Top, ww, wh;
  174.  
  175.     ComputeFont( SP_Main_Width, SP_Main_Height );
  176.  
  177.     ww = ComputeX( SP_Main_Width );
  178.     wh = ComputeY( SP_Main_Height );
  179.  
  180.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  181.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  182.  
  183.     if ( ! ( g = CreateContext( &SP_Main_GList )))
  184.         return( 1L );
  185.  
  186.     for( lc = 0, tc = 0; lc < SP_Main__CNT; lc++ ) {
  187.  
  188.         CopyMem((char * )&SP_Main_NGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  189.  
  190.         ng.ng_VisualInfo = VisualInfo;
  191.         ng.ng_TextAttr   = Font;
  192.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  193.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  194.         ng.ng_Width      = ComputeX( ng.ng_Width );
  195.         ng.ng_Height     = ComputeY( ng.ng_Height);
  196.  
  197.         SP_Main_Gadgets[ lc ] = g = CreateGadgetA((ULONG)SP_Main_GTypes[ lc ], g, &ng, ( struct TagItem * )&SP_Main_GTags[ tc ] );
  198.  
  199.         while( SP_Main_GTags[ tc ] ) tc += 2;
  200.         tc++;
  201.  
  202.         if ( NOT g )
  203.             return( 2L );
  204.     }
  205.  
  206.     if ( ! ( SP_Main_Wnd = OpenWindowTags( NULL,
  207.                 WA_Left,    wleft,
  208.                 WA_Top,        wtop,
  209.                 WA_Width,    ww + OffX + Scr->WBorRight,
  210.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  211.                 WA_IDCMP,    BUTTONIDCMP|LISTVIEWIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  212.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
  213.                 WA_Gadgets,    SP_Main_GList,
  214.                 WA_Title,    SP_Main_Wdt,
  215.                 WA_ScreenTitle,    "SuperPlay V4.1",
  216.                 TAG_DONE )))
  217.     return( 4L );
  218.  
  219.     GT_RefreshWindow( SP_Main_Wnd, NULL );
  220.  
  221.     SP_Main_Render();
  222.  
  223.     return( 0L );
  224. }
  225.  
  226. void CloseSP_Main_Window( void )
  227. {
  228.     if ( SP_Main_Wnd        ) {
  229.         CloseWindow( SP_Main_Wnd );
  230.         SP_Main_Wnd = NULL;
  231.     }
  232.  
  233.     if ( SP_Main_GList      ) {
  234.         FreeGadgets( SP_Main_GList );
  235.         SP_Main_GList = NULL;
  236.     }
  237. }
  238.  
  239.